<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>springDataJPA总结 | Jeremy Sze的博客</title>
    <meta property="og:title" content="springDataJPA总结 - Jeremy Sze的博客">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2018-10-21T08:36:54&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2018-10-21T08:36:54&#43;08:00'>
        
    <meta name="Keywords" content="java,博客">
    <meta name="description" content="springDataJPA总结">
        
    <meta name="author" content="Jeremy Sze">
    <meta property="og:url" content="https://laoer123.gitee.io/laoer123/post/springDataJPA%E6%80%BB%E7%BB%93/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href='/laoer123/css/normalize.css'>
    <link rel="stylesheet" href='/laoer123/css/style.css'>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({
        google_ad_client: "ca-pub-4031353640611810",
        enable_page_level_ads: true
    });
    </script>
    


    
    
        <link rel="stylesheet" href='/laoer123/css/douban.css'>
    
        <link rel="stylesheet" href='/laoer123/css/other.css'>
    
</head>


<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://laoer123.gitee.io/laoer123">
                        Jeremy Sze的博客
                    </a>
                
                <p class="description">专注于Java、JavaScript、软件开发、web开发、分布式，微服务系统开发</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://laoer123.gitee.io/laoer123">首页</a>
                    
                    <a  href="https://laoer123.gitee.io/laoer123/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#spring-data-jpa概述">Spring Data JPA概述</a></li>
    <li><a href="#spring-data-jpa-与-jpa和hibernate之间的关系">Spring Data JPA 与 JPA和hibernate之间的关系</a></li>
    <li><a href="#编写applicationcontextxml">编写applicationContext.xml</a></li>
    <li><a href="#编写实体类">编写实体类</a></li>
    <li><a href="#编写符合spring-data-jpa规范的dao层接口">编写符合Spring Data JPA规范的Dao层接口</a></li>
    <li><a href="#test增删改查">test增删改查</a></li>
    <li><a href="#spring-data-jpa的内部原理剖析">Spring Data JPA的内部原理剖析</a>
      <ul>
        <li><a href="#spring-data-jpa的常用接口分析">Spring Data JPA的常用接口分析</a></li>
      </ul>
    </li>
    <li><a href="#spring-data-jpa的实现过程">Spring Data JPA的实现过程</a>
      <ul>
        <li><a href="#代理对象中方法调用的分析">代理对象中方法调用的分析</a></li>
      </ul>
    </li>
    <li><a href="#spring-data-jpa完整的调用过程分析">Spring Data JPA完整的调用过程分析</a></li>
    <li><a href="#使用spring-data-jpa中接口定义的方法进行查询">使用Spring Data JPA中接口定义的方法进行查询</a>
      <ul>
        <li><a href="#继承jparepository后的方法列表">继承JpaRepository后的方法列表</a></li>
      </ul>
    </li>
    <li><a href="#继承jpaspecificationexecutor的方法列表">继承JpaSpecificationExecutor的方法列表</a></li>
    <li><a href="#使用jpql的方式查询">使用JPQL的方式查询</a>
      <ul>
        <li><a href="#使用sql语句查询">使用SQL语句查询</a></li>
      </ul>
    </li>
    <li><a href="#方法命名规则查询">方法命名规则查询</a></li>
    <li><a href="#具体的关键字使用方法和生产成sql如下表所示">具体的关键字，使用方法和生产成SQL如下表所示</a></li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">springDataJPA总结</h1>
        </header>
        <date class="post-meta meta-date">
            2018年10月21日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='https://laoer123.gitee.io/categories/spring'>spring</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <h2 id="spring-data-jpa概述">Spring Data JPA概述</h2>
<p>  Spring Data JPA 是 Spring 基于 ORM 框架、JPA 规范的基础上封装的一套JPA应用框架，可使开发者用极简的代码即可实现对数据库的访问和操作。它提供了包括增删改查等在内的常用功能，且易于扩展！学习并使用 Spring Data JPA 可以极大提高开发效率！</p>
<p>  Spring Data JPA 让我们解脱了DAO层的操作，基本上所有CRUD都可以依赖于它来实现,在实际的工作工程中，推荐使用Spring Data JPA + ORM（如：hibernate）完成操作，这样在切换不同的ORM框架时提供了极大的方便，同时也使数据库层操作更加简单，方便解耦</p>
<p>  SpringData Jpa 极大简化了数据库访问层代码。 如何简化的呢？<br>
$\color{red}{使用了SpringDataJpa，我们的dao层中只需要写接口，就自动具有了增删改查、分页查询等方法。}$</p>
<h2 id="spring-data-jpa-与-jpa和hibernate之间的关系">Spring Data JPA 与 JPA和hibernate之间的关系</h2>
<p>  JPA是一套规范，内部是有接口和抽象类组成的。hibernate是一套成熟的ORM框架，而且Hibernate实现了JPA规范，所以也可以称hibernate为JPA的一种实现方式，我们使用JPA的API编程，意味着站在更高的角度上看待问题（面向接口编程）</p>
<p>  Spring Data JPA是Spring提供的一套对JPA操作更加高级的封装，是在JPA规范下的专门用来进行数据持久化的解决方案。
<img src="/img/springDataJPA.png" alt="alt springDataJPA"></p>
<h2 id="编写applicationcontextxml">编写applicationContext.xml</h2>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">62
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">63
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">64
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">65
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">66
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">67
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">68
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">69
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">70
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">71
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">72
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">73
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">74
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">75
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">76
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-xml" data-lang="xml"><span style="color:#999;font-weight:bold;font-style:italic">&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;</span>
<span style="color:#000080">&lt;beans</span> <span style="color:#008080">xmlns=</span><span style="color:#d14">&#34;http://www.springframework.org/schema/beans&#34;</span>
       <span style="color:#008080">xmlns:xsi=</span><span style="color:#d14">&#34;http://www.w3.org/2001/XMLSchema-instance&#34;</span> <span style="color:#008080">xmlns:aop=</span><span style="color:#d14">&#34;http://www.springframework.org/schema/aop&#34;</span>
       <span style="color:#008080">xmlns:context=</span><span style="color:#d14">&#34;http://www.springframework.org/schema/context&#34;</span>
       <span style="color:#008080">xmlns:jdbc=</span><span style="color:#d14">&#34;http://www.springframework.org/schema/jdbc&#34;</span> <span style="color:#008080">xmlns:tx=</span><span style="color:#d14">&#34;http://www.springframework.org/schema/tx&#34;</span>
       <span style="color:#008080">xmlns:jpa=</span><span style="color:#d14">&#34;http://www.springframework.org/schema/data/jpa&#34;</span> <span style="color:#008080">xmlns:task=</span><span style="color:#d14">&#34;http://www.springframework.org/schema/task&#34;</span>
       <span style="color:#008080">xsi:schemaLocation=</span><span style="color:#d14">&#34;
</span><span style="color:#d14">		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
</span><span style="color:#d14">		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
</span><span style="color:#d14">		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
</span><span style="color:#d14">		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
</span><span style="color:#d14">		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
</span><span style="color:#d14">		http://www.springframework.org/schema/data/jpa
</span><span style="color:#d14">		http://www.springframework.org/schema/data/jpa/spring-jpa.xsd&#34;</span><span style="color:#000080">&gt;</span>

    <span style="color:#998;font-style:italic">&lt;!--datasource配置数据库连接池--&gt;</span>

    <span style="color:#000080">&lt;bean</span> <span style="color:#008080">id=</span><span style="color:#d14">&#34;dataSource&#34;</span> <span style="color:#008080">class=</span><span style="color:#d14">&#34;com.mchange.v2.c3p0.ComboPooledDataSource&#34;</span><span style="color:#000080">&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;driverClass&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;com.mysql.jdbc.Driver&#34;</span><span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;jdbcUrl&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;jdbc:mysql://localhost:3306/jpa?characterEncoding=utf8&#34;</span><span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;user&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;root&#34;</span><span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;password&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;root&#34;</span><span style="color:#000080">/&gt;</span>
     <span style="color:#000080">&lt;/bean&gt;</span>

    <span style="color:#998;font-style:italic">&lt;!-- 2.配置entityManagerFactory --&gt;</span>
    <span style="color:#000080">&lt;bean</span> <span style="color:#008080">id=</span><span style="color:#d14">&#34;entityManagerFactory&#34;</span> <span style="color:#008080">class=</span><span style="color:#d14">&#34;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&#34;</span><span style="color:#000080">&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;dataSource&#34;</span> <span style="color:#008080">ref=</span><span style="color:#d14">&#34;dataSource&#34;</span> <span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;packagesToScan&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;com.java1995.entity&#34;</span> <span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;persistenceProvider&#34;</span><span style="color:#000080">&gt;</span>
            <span style="color:#000080">&lt;bean</span> <span style="color:#008080">class=</span><span style="color:#d14">&#34;org.hibernate.jpa.HibernatePersistenceProvider&#34;</span> <span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;/property&gt;</span>
        <span style="color:#998;font-style:italic">&lt;!--JPA的供应商适配器--&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;jpaVendorAdapter&#34;</span><span style="color:#000080">&gt;</span>
            <span style="color:#000080">&lt;bean</span> <span style="color:#008080">class=</span><span style="color:#d14">&#34;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&#34;</span><span style="color:#000080">&gt;</span>
                <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;generateDdl&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;false&#34;</span> <span style="color:#000080">/&gt;</span>
                <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;database&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;MYSQL&#34;</span> <span style="color:#000080">/&gt;</span>
                <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;databasePlatform&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;org.hibernate.dialect.MySQLDialect&#34;</span> <span style="color:#000080">/&gt;</span>
                <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;showSql&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;true&#34;</span> <span style="color:#000080">/&gt;</span>
            <span style="color:#000080">&lt;/bean&gt;</span>
        <span style="color:#000080">&lt;/property&gt;</span>
        <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;jpaDialect&#34;</span><span style="color:#000080">&gt;</span>
            <span style="color:#000080">&lt;bean</span> <span style="color:#008080">class=</span><span style="color:#d14">&#34;org.springframework.orm.jpa.vendor.HibernateJpaDialect&#34;</span> <span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;/property&gt;</span>
    <span style="color:#000080">&lt;/bean&gt;</span>

<span style="color:#998;font-style:italic">&lt;!--3.事务管理器--&gt;</span>
<span style="color:#998;font-style:italic">&lt;!--JPA事务管理器--&gt;</span>
<span style="color:#000080">&lt;bean</span> <span style="color:#008080">id=</span><span style="color:#d14">&#34;transactionManager&#34;</span> <span style="color:#008080">class=</span><span style="color:#d14">&#34;org.springframework.orm.jpa.JpaTransactionManager&#34;</span><span style="color:#000080">&gt;</span>
    <span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;entityManagerFactory&#34;</span> <span style="color:#008080">ref=</span><span style="color:#d14">&#34;entityManagerFactory&#34;</span><span style="color:#000080">/&gt;</span>
<span style="color:#000080">&lt;/bean&gt;</span>
    
    <span style="color:#998;font-style:italic">&lt;!--整合spring data jpa--&gt;</span>
    <span style="color:#000080">&lt;jpa:repositories</span> <span style="color:#008080">base-package=</span><span style="color:#d14">&#34;com.java1995.dao&#34;</span> <span style="color:#008080">transaction-manager-ref=</span><span style="color:#d14">&#34;transactionManager&#34;</span> <span style="color:#008080">entity-manager-factory-ref=</span><span style="color:#d14">&#34;entityManagerFactory&#34;</span><span style="color:#000080">&gt;&lt;/jpa:repositories&gt;</span>

    <span style="color:#998;font-style:italic">&lt;!-- 4.txAdvice--&gt;</span>
    <span style="color:#000080">&lt;tx:advice</span> <span style="color:#008080">id=</span><span style="color:#d14">&#34;txAdvice&#34;</span> <span style="color:#008080">transaction-manager=</span><span style="color:#d14">&#34;transactionManager&#34;</span><span style="color:#000080">&gt;</span>
        <span style="color:#000080">&lt;tx:attributes&gt;</span>
            <span style="color:#000080">&lt;tx:method</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;save*&#34;</span> <span style="color:#008080">propagation=</span><span style="color:#d14">&#34;REQUIRED&#34;</span><span style="color:#000080">/&gt;</span>
            <span style="color:#000080">&lt;tx:method</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;insert*&#34;</span> <span style="color:#008080">propagation=</span><span style="color:#d14">&#34;REQUIRED&#34;</span><span style="color:#000080">/&gt;</span>
            <span style="color:#000080">&lt;tx:method</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;update*&#34;</span> <span style="color:#008080">propagation=</span><span style="color:#d14">&#34;REQUIRED&#34;</span><span style="color:#000080">/&gt;</span>
            <span style="color:#000080">&lt;tx:method</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;delete*&#34;</span> <span style="color:#008080">propagation=</span><span style="color:#d14">&#34;REQUIRED&#34;</span><span style="color:#000080">/&gt;</span>
            <span style="color:#000080">&lt;tx:method</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;get*&#34;</span> <span style="color:#008080">read-only=</span><span style="color:#d14">&#34;true&#34;</span><span style="color:#000080">/&gt;</span>
            <span style="color:#000080">&lt;tx:method</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;find*&#34;</span> <span style="color:#008080">read-only=</span><span style="color:#d14">&#34;true&#34;</span><span style="color:#000080">/&gt;</span>
            <span style="color:#000080">&lt;tx:method</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;*&#34;</span> <span style="color:#008080">propagation=</span><span style="color:#d14">&#34;REQUIRED&#34;</span><span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;/tx:attributes&gt;</span>
    <span style="color:#000080">&lt;/tx:advice&gt;</span>
    <span style="color:#998;font-style:italic">&lt;!-- 5.aop--&gt;</span>
    <span style="color:#000080">&lt;aop:config&gt;</span>
        <span style="color:#000080">&lt;aop:pointcut</span> <span style="color:#008080">id=</span><span style="color:#d14">&#34;pointcut&#34;</span> <span style="color:#008080">expression=</span><span style="color:#d14">&#34;execution(* com.java1995.service.*.*(..))&#34;</span> <span style="color:#000080">/&gt;</span>
        <span style="color:#000080">&lt;aop:advisor</span> <span style="color:#008080">advice-ref=</span><span style="color:#d14">&#34;txAdvice&#34;</span> <span style="color:#008080">pointcut-ref=</span><span style="color:#d14">&#34;pointcut&#34;</span> <span style="color:#000080">/&gt;</span>
    <span style="color:#000080">&lt;/aop:config&gt;</span>
    <span style="color:#000080">&lt;context:component-scan</span> <span style="color:#008080">base-package=</span><span style="color:#d14">&#34;com.java1995&#34;</span><span style="color:#000080">&gt;&lt;/context:component-scan&gt;</span>

    <span style="color:#998;font-style:italic">&lt;!--组装其它 配置文件--&gt;</span>

<span style="color:#000080">&lt;/beans&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="编写实体类">编写实体类</h2>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">62
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">63
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">64
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">65
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">66
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">67
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">68
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">69
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">70
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">71
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">72
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">73
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">74
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">75
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">76
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">77
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">78
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">79
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">80
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">81
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">82
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">83
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">84
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">85
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">86
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">87
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">88
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">89
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">90
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">91
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">92
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">93
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">94
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">95
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">96
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">97
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">98
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">99
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">package</span> <span style="color:#555">com.java1995.entity</span><span style="color:#000;font-weight:bold">;</span>

<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">javax.persistence.*</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">java.io.Serializable</span><span style="color:#000;font-weight:bold">;</span>

<span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic"> * @author Jeremy SZE
</span><span style="color:#998;font-style:italic"> * 
</span><span style="color:#998;font-style:italic"> */</span>
<span style="color:#3c5d5d;font-weight:bold">@Entity</span>
<span style="color:#3c5d5d;font-weight:bold">@Table</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cst_customer&#34;</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">Customer</span> <span style="color:#000;font-weight:bold">implements</span> Serializable <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#3c5d5d;font-weight:bold">@Id</span>
    <span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_id&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#3c5d5d;font-weight:bold">@GeneratedValue</span><span style="color:#000;font-weight:bold">(</span>strategy <span style="color:#000;font-weight:bold">=</span> GenerationType<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">IDENTITY</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> Long custId<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_name&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String custName<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name <span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_source&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String custSource<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name <span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_industry&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String custIndustry<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_level&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String custLevel<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_address&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String custAddress<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_phone&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String custPhone<span style="color:#000;font-weight:bold">;</span>

    <span style="color:#000;font-weight:bold">public</span> Long <span style="color:#900;font-weight:bold">getCustId</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> custId<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustId</span><span style="color:#000;font-weight:bold">(</span>Long custId<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custId</span> <span style="color:#000;font-weight:bold">=</span> custId<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustName</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> custName<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustName</span><span style="color:#000;font-weight:bold">(</span>String custName<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custName</span> <span style="color:#000;font-weight:bold">=</span> custName<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustSource</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> custSource<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustSource</span><span style="color:#000;font-weight:bold">(</span>String custSource<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custSource</span> <span style="color:#000;font-weight:bold">=</span> custSource<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustIndustry</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> custIndustry<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustIndustry</span><span style="color:#000;font-weight:bold">(</span>String custIndustry<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custIndustry</span> <span style="color:#000;font-weight:bold">=</span> custIndustry<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustLevel</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> custLevel<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustLevel</span><span style="color:#000;font-weight:bold">(</span>String custLevel<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custLevel</span> <span style="color:#000;font-weight:bold">=</span> custLevel<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustAddress</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> custAddress<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustAddress</span><span style="color:#000;font-weight:bold">(</span>String custAddress<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custAddress</span> <span style="color:#000;font-weight:bold">=</span> custAddress<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustPhone</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> custPhone<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustPhone</span><span style="color:#000;font-weight:bold">(</span>String custPhone<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custPhone</span> <span style="color:#000;font-weight:bold">=</span> custPhone<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#3c5d5d;font-weight:bold">@Override</span>
    <span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">toString</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">return</span> <span style="color:#d14">&#34;Customer{&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;custId=&#34;</span> <span style="color:#000;font-weight:bold">+</span> custId <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;, custName=&#39;&#34;</span> <span style="color:#000;font-weight:bold">+</span> custName <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#39;\&#39;&#39;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;, custSource=&#39;&#34;</span> <span style="color:#000;font-weight:bold">+</span> custSource <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#39;\&#39;&#39;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;, custIndustry=&#39;&#34;</span> <span style="color:#000;font-weight:bold">+</span> custIndustry <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#39;\&#39;&#39;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;, custLevel=&#39;&#34;</span> <span style="color:#000;font-weight:bold">+</span> custLevel <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#39;\&#39;&#39;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;, custAddress=&#39;&#34;</span> <span style="color:#000;font-weight:bold">+</span> custAddress <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#39;\&#39;&#39;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;, custPhone=&#39;&#34;</span> <span style="color:#000;font-weight:bold">+</span> custPhone <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#39;\&#39;&#39;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#39;}&#39;</span><span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>

</code></pre></td></tr></table>
</div>
</div><h2 id="编写符合spring-data-jpa规范的dao层接口">编写符合Spring Data JPA规范的Dao层接口</h2>
<p>  Spring Data JPA是spring提供的一款对于数据访问层（Dao层）的框架，使用Spring Data JPA，只需要按照框架的规范提供dao接口，不需要实现类就可以完成数据库的增删改查、分页查询等方法的定义，极大的简化了我们的开发过程。</p>
<p>$\color{red}{在Spring Data JPA中，对于定义符合规范的Dao层接口，我们只需要遵循以下几点就可以了：}$</p>
<ol>
<li>创建一个Dao层接口，并实现JpaRepository和JpaSpecificationExecutor</li>
<li>提供相应的泛型</li>
</ol>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">9
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic"> * JpaRepository&lt;实体类类型，主键类型&gt;：用来完成基本CRUD操作
</span><span style="color:#998;font-style:italic"> * JpaSpecificationExecutor&lt;实体类类型&gt;：用于复杂查询（分页等查询操作）
</span><span style="color:#998;font-style:italic"> */</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">interface</span> <span style="color:#458;font-weight:bold">CustomerDao</span> <span style="color:#000;font-weight:bold">extends</span> JpaRepository<span style="color:#000;font-weight:bold">&lt;</span>Customer<span style="color:#000;font-weight:bold">,</span> Long<span style="color:#000;font-weight:bold">&gt;,</span> 
JpaSpecificationExecutor<span style="color:#000;font-weight:bold">&lt;</span>Customer<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#000;font-weight:bold">{</span>

<span style="color:#000;font-weight:bold">}</span>

</code></pre></td></tr></table>
</div>
</div><p>这样我们就定义好了一个符合Spring Data JPA规范的Dao层接口<br>
这样我们完成了Spring Data JPA的环境搭建，并且编写了符合Spring Data JPA 规范的Dao层接口之后，就可以使用定义好的Dao层接口进行客户的基本CRUD操作</p>
<h2 id="test增删改查">test增删改查</h2>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 新增
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">testSave</span><span style="color:#000;font-weight:bold">(){</span>
        Customer customer <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> Customer<span style="color:#000;font-weight:bold">();</span>

        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustAddress</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;汕尾市&#34;</span><span style="color:#000;font-weight:bold">);</span>
        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustPhone</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;10086&#34;</span><span style="color:#000;font-weight:bold">);</span>
        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustName</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;黄思聪&#34;</span><span style="color:#000;font-weight:bold">);</span>
        customerDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">save</span><span style="color:#000;font-weight:bold">(</span>customer<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 带上id是更新，不带id是添加  save()
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">testUpdate</span><span style="color:#000;font-weight:bold">(){</span>

        Customer customer1 <span style="color:#000;font-weight:bold">=</span> customerDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">findOne</span><span style="color:#000;font-weight:bold">(</span>4l<span style="color:#000;font-weight:bold">);</span>
        Customer customer <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> Customer<span style="color:#000;font-weight:bold">();</span>
        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustId</span><span style="color:#000;font-weight:bold">(</span>customer1<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getCustId</span><span style="color:#000;font-weight:bold">());</span>
        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustAddress</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;汕尾市&#34;</span><span style="color:#000;font-weight:bold">);</span>
        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustPhone</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;10086&#34;</span><span style="color:#000;font-weight:bold">);</span>
        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustName</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;黄思聪&#34;</span><span style="color:#000;font-weight:bold">);</span>
        customerDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">save</span><span style="color:#000;font-weight:bold">(</span>customer<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 删除  选根据id进行查询，之后再删除
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">testDelete</span><span style="color:#000;font-weight:bold">(){</span>


        customerDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">delete</span><span style="color:#000;font-weight:bold">(</span>5L<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#998;font-style:italic">/***
</span><span style="color:#998;font-style:italic">     * 根据id进行查询
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">findById</span><span style="color:#000;font-weight:bold">(){</span>

        Customer customer <span style="color:#000;font-weight:bold">=</span> customerDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">findOne</span><span style="color:#000;font-weight:bold">(</span>1l<span style="color:#000;font-weight:bold">);</span>

        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>customer<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>


</code></pre></td></tr></table>
</div>
</div><h2 id="spring-data-jpa的内部原理剖析">Spring Data JPA的内部原理剖析</h2>
<h3 id="spring-data-jpa的常用接口分析">Spring Data JPA的常用接口分析</h3>
<p>  在客户的案例中，我们发现在自定义的CustomerDao中，并没有提供任何方法就可以使用其中的很多方法，那么这些方法究竟是怎么来的呢？答案很简单，对于我们自定义的Dao接口，由于继承了JpaRepository和JpaSpecificationExecutor，所以我们可以使用这两个接口的所有方法。
<img src="/img/jpa%E5%8E%9F%E7%90%86.png" alt="alt jpa原理"></p>
<p>  在使用Spring Data JPA时，一般实现JpaRepository和JpaSpecificationExecutor接口，这样就可以使用这些接口中定义的方法，但是这些方法都只是一些声明，没有具体的实现方式，那么在 Spring Data JPA中它又是怎么实现的呢？</p>
<h2 id="spring-data-jpa的实现过程">Spring Data JPA的实现过程</h2>
<p>  通过对客户案例，以debug断点调试的方式，通过分析Spring Data JPA的原来来分析程序的执行过程
<img src="/img/%E4%BB%A3%E7%90%86.png" alt="alt 代理"></p>
<p>断点执行到方法上时，我们可以发现注入的customerDao对象，本质上是通过JdkDynamicAopProxy生成的一个代理对象</p>
<h3 id="代理对象中方法调用的分析">代理对象中方法调用的分析</h3>
<p>  当程序执行的时候，会通过JdkDynamicAopProxy的invoke方法，对customerDao对象生成动态代理对象。根据对Spring Data JPA介绍而知，要想进行findOne查询方法，最终还是会出现JPA规范的API完成操作，那么这些底层代码存在于何处呢？答案很简单，都隐藏在通过JdkDynamicAopProxy生成的动态代理对象当中，而这个动态代理对象就是SimpleJpaRepository
<img src="/img/simplePorxy.png" alt="alt simplePorxy"></p>
<p>通过SimpleJpaRepository的源码分析，定位到了findOne方法，在此方法中，返回em.find()的返回结果，那么em又是什么呢？ 
<img src="/img/findOne.png" alt="alt findOne"></p>
<p>  带着问题继续查找em对象，我们发现em就是EntityManager对象，而他是JPA原生的实现方式，所以我们得到结论Spring Data JPA只是对标准JPA操作进行了进一步封装，简化了Dao层代码的开发</p>
<h2 id="spring-data-jpa完整的调用过程分析">Spring Data JPA完整的调用过程分析</h2>
<p><img src="/img/jpa%E5%AE%8C%E6%95%B4%E8%B0%83%E7%94%A8%E5%8E%9F%E7%90%86.png" alt="alt jpa完整调用原理"></p>
<h2 id="使用spring-data-jpa中接口定义的方法进行查询">使用Spring Data JPA中接口定义的方法进行查询</h2>
<h3 id="继承jparepository后的方法列表">继承JpaRepository后的方法列表</h3>
<p><img src="/img/jpa%E6%8E%A5%E5%8F%A3%E6%96%B9%E6%B3%95.png" alt="alt jpa接口方法"></p>
<h2 id="继承jpaspecificationexecutor的方法列表">继承JpaSpecificationExecutor的方法列表</h2>
<p><img src="/img/JpaSpecificationExecutor.png" alt="alt JpaSpecificationExecutor"></p>
<h2 id="使用jpql的方式查询">使用JPQL的方式查询</h2>
<p>使用Spring Data JPA提供的查询方法已经可以解决大部分的应用场景，但是对于某些业务来说，我们还需要灵活的构造查询条件，这时就可以使用@Query注解，结合JPQL的语句方式完成查询</p>
<p>$\color{red}{@Query 注解的使用非常简单，只需在方法上面标注该注解，同时提供一个JPQL查询语句即可}$</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">interface</span> <span style="color:#458;font-weight:bold">CustomerDao</span> <span style="color:#000;font-weight:bold">extends</span> JpaRepository<span style="color:#000;font-weight:bold">&lt;</span>Customer<span style="color:#000;font-weight:bold">,</span> Long<span style="color:#000;font-weight:bold">&gt;,</span>JpaSpecificationExecutor<span style="color:#000;font-weight:bold">&lt;</span>Customer<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#000;font-weight:bold">{</span>    
    <span style="color:#998;font-style:italic">//@Query 使用jpql的方式查询。
</span><span style="color:#998;font-style:italic"></span>    <span style="color:#3c5d5d;font-weight:bold">@Query</span><span style="color:#000;font-weight:bold">(</span>value<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;from Customer&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">public</span> List<span style="color:#000;font-weight:bold">&lt;</span>Customer<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">findAllCustomer</span><span style="color:#000;font-weight:bold">();</span>
    
    <span style="color:#998;font-style:italic">//@Query 使用jpql的方式查询。?1代表参数的占位符，其中1对应方法中的参数索引
</span><span style="color:#998;font-style:italic"></span>    <span style="color:#3c5d5d;font-weight:bold">@Query</span><span style="color:#000;font-weight:bold">(</span>value<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;from Customer where custName = ?1&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">public</span> Customer <span style="color:#900;font-weight:bold">findCustomer</span><span style="color:#000;font-weight:bold">(</span>String custName<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>

</code></pre></td></tr></table>
</div>
</div><p>  此外，也可以通过使用 @Query 来执行一个更新操作，为此，我们需要在使用 @Query 的同时，用 @Modifying 来将该操作标识为修改查询，这样框架最终会生成一个更新的操作，而非查询</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#3c5d5d;font-weight:bold">@Query</span><span style="color:#000;font-weight:bold">(</span>value<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;update Customer set custName = ?1 where custId = ?2&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#3c5d5d;font-weight:bold">@Modifying</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">updateCustomer</span><span style="color:#000;font-weight:bold">(</span>String custName<span style="color:#000;font-weight:bold">,</span>Long custId<span style="color:#000;font-weight:bold">);</span>

</code></pre></td></tr></table>
</div>
</div><p>测试方法中要加入两个注解</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#3c5d5d;font-weight:bold">@Transactional</span>
    <span style="color:#3c5d5d;font-weight:bold">@Rollback</span><span style="color:#000;font-weight:bold">(</span>value <span style="color:#000;font-weight:bold">=</span><span style="color:#000;font-weight:bold">false</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">public</span>  <span style="color:#458;font-weight:bold">void</span>  <span style="color:#900;font-weight:bold">updateCustomer</span><span style="color:#000;font-weight:bold">(){</span>

        Customer customer <span style="color:#000;font-weight:bold">=</span> customerDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">findOne</span><span style="color:#000;font-weight:bold">(</span>1l<span style="color:#000;font-weight:bold">);</span>
        customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustAddress</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;汕尾市&#34;</span><span style="color:#000;font-weight:bold">);</span>

        customerDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">updateCustomer</span><span style="color:#000;font-weight:bold">(</span>customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getCustName</span><span style="color:#000;font-weight:bold">(),</span>customer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getCustId</span><span style="color:#000;font-weight:bold">());</span>

    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="使用sql语句查询">使用SQL语句查询</h3>
<p>pring Data JPA同样也支持sql语句的查询，如下：</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * nativeQuery : 使用本地sql的方式查询
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Query</span><span style="color:#000;font-weight:bold">(</span>value<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;select * from cst_customer&#34;</span><span style="color:#000;font-weight:bold">,</span>nativeQuery<span style="color:#000;font-weight:bold">=</span><span style="color:#000;font-weight:bold">true</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">findSql</span><span style="color:#000;font-weight:bold">();</span>

</code></pre></td></tr></table>
</div>
</div><h2 id="方法命名规则查询">方法命名规则查询</h2>
<p>  顾名思义，方法命名规则查询就是根据方法的名字，就能创建查询。只需要按照Spring Data JPA提供的方法命名规则定义方法的名称，就可以完成查询工作。Spring Data JPA在程序执行的时候会根据方法名称进行解析，并自动生成查询语句进行查询</p>
<p>  按照Spring Data JPA 定义的规则，查询方法以findBy开头，涉及条件查询时，条件的属性用条件关键字连接，要注意的是：条件属性首字母需大写。框架在进行方法名解析时，会先把方法名多余的前缀截取掉，然后对剩下部分进行解析。</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#998;font-style:italic">//方法命名方式查询（根据客户名称查询客户）
</span><span style="color:#998;font-style:italic"></span>    <span style="color:#000;font-weight:bold">public</span> Customer <span style="color:#900;font-weight:bold">findByCustName</span><span style="color:#000;font-weight:bold">(</span>String custName<span style="color:#000;font-weight:bold">);</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="具体的关键字使用方法和生产成sql如下表所示">具体的关键字，使用方法和生产成SQL如下表所示</h2>
<p><img src="/img/jpa%E6%96%B9%E6%B3%95%E5%90%8D%E6%9F%A5%E8%AF%A21.png" alt="alt jpa方法名查询1"><br>
<img src="/img/jpa%E6%96%B9%E6%B3%95%E5%90%8D%E6%9F%A5%E8%AF%A22.png" alt="alt jpa方法名查询2"><br>
<img src="/img/jpa%E6%96%B9%E6%B3%95%E5%90%8D%E6%9F%A5%E8%AF%A23.png" alt="alt jpa方法名查询3"><br>
<img src="/img/jpa%E6%96%B9%E6%B3%95%E5%90%8D%E6%9F%A5%E8%AF%A24.png" alt="alt jpa方法名查询4"></p>

        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://laoer123.gitee.io/laoer123">Jeremy Sze</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://laoer123.gitee.io/laoer123/post/springDataJPA%E6%80%BB%E7%BB%93/">https://laoer123.gitee.io/laoer123/post/springDataJPA%E6%80%BB%E7%BB%93/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/laoer123/post/JPA/">JPA总结</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E6%A8%A1%E6%9D%BF%E6%A8%A1%E5%BC%8F/">java之设计模式_模板模式</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F/">java之设计模式_策略模式</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F/">java之设计模式_观察者模式</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F/">java之设计模式_单例模式</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='https://laoer123.gitee.io/tags/springDataJPA'>springDataJPA</a></li>
                
            </ul>
            
        </div>
    </article>
    
    <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "yourdiscussshortname" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

    
    
</div>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://laoer123.gitee.io/laoer123/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://laoer123.gitee.io/laoer123">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/springcloud%E4%B8%8EspringcloudAlibaba%E6%80%BB%E7%BB%93/" title="springcloud与springcloudAlibaba总结">springcloud与springcloudAlibaba总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Seata%E6%80%BB%E7%BB%93/" title="Seata总结">Seata总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/OpenFegin%E6%80%BB%E7%BB%93/" title="OpenFegin总结">OpenFegin总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudGateWay%E6%80%BB%E7%BB%93/" title="SpringCloudGateWay总结">SpringCloudGateWay总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudRibbon/" title="SpringCloudRibbon总结">SpringCloudRibbon总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E6%B3%A8%E5%86%8C%E4%B8%8E%E5%8F%91%E7%8E%B0/" title="Nacos配置注册与发现">Nacos配置注册与发现</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86%E6%BC%94%E7%A4%BA/" title="Nacos配置管理演示">Nacos配置管理演示</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E6%80%BB%E7%BB%93/" title="什么是Nacos">什么是Nacos</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%96%B0%E6%89%8B%E6%8C%87%E5%8D%97/" title="Sentinel新手指南">Sentinel新手指南</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%8E%A7%E5%88%B6%E5%8F%B0/" title="Sentinel控制台">Sentinel控制台</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">分类</h3>
<ul class="widget-list">
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/Linux/">Linux (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/NoSql%E6%95%B0%E6%8D%AE%E5%BA%93/">NoSql数据库 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloud/">SpringCloud (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibaba/">SpringCloudAlibaba (11)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibabaSpringCloud/">SpringCloudAlibaba,SpringCloud (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/docker/">docker (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/java%E5%9F%BA%E7%A1%80/">java基础 (10)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/spring/">spring (4)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E4%BA%8B%E5%8A%A1/">事务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E5%BE%AE%E6%9C%8D%E5%8A%A1/">前端微服务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E6%A1%86%E6%9E%B6/">前端框架 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90/">持续集成 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/">搜索引擎 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%B1%82%E6%A1%86%E6%9E%B6/">数据层框架 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库 (5)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/">服务器 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9E%B6%E6%9E%84/">架构 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/">消息中间件 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%BC%93%E5%AD%98/">缓存 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%AE%A4%E8%AF%81/">认证 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%BF%90%E7%BB%B4/">运维 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E9%83%A8%E7%BD%B2/">部署 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title">标签</h3>
<div class="tagcloud">
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Dubbo/">Dubbo</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ES6/">ES6</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElasticSearch/">ElasticSearch</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElementUI/">ElementUI</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Eureka/">Eureka</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Feign/">Feign</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JDBCTemplate/">JDBCTemplate</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JPA/">JPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JWT/">JWT</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Jenkins/">Jenkins</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E5%9F%BA%E7%A1%80/">Linux基础</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E9%85%8D%E7%BD%AE%E8%81%94%E7%BD%91/">Linux配置联网</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/MongoDB/">MongoDB</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Nacos/">Nacos</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ORACLE/">ORACLE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/OpenFegin/">OpenFegin</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/RabbitMQ/">RabbitMQ</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Seata/">Seata</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Sentinel/">Sentinel</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudGateWay/">SpringCloudGateWay</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudRibbon/">SpringCloudRibbon</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudSpringCloudAlibaba/">SpringCloud,SpringCloudAlibaba</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/VUE/">VUE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/docker/">docker</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/git/">git</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/gogs/">gogs</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/hystrix/">hystrix</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/mysql/">mysql</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nginx/">nginx</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nodeJS/">nodeJS</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/npm/">npm</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springCache/">springCache</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springDataJPA/">springDataJPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springboot/">springboot</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudbus/">springcloudbus</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudconfig/">springcloudconfig</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springdataredis/">springdataredis</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/zuul/">zuul</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E4%BA%8B%E5%8A%A1/">分布式事务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%9B%E5%BB%BA%E6%A8%A1%E5%BC%8F/">创建模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%BE%AE%E6%9C%8D%E5%8A%A1/">微服务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%8E%92%E5%BA%8F/">排序</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%9C%8D%E5%8A%A1%E9%95%9C%E5%83%8F%E7%9A%84%E6%9E%84%E5%BB%BA%E4%B8%8E%E9%83%A8%E7%BD%B2/">服务镜像的构建与部署</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E7%BB%93%E6%9E%84%E6%A8%A1%E5%BC%8F/">结构模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%A1%8C%E4%B8%BA%E6%A8%A1%E5%BC%8F/">行为模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">设计模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%BF%90%E7%BB%B4/">运维</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://www.cnblogs.com/Jeremy95-Sze/" title="Jeremy Sze的博客">Jeremy Sze的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://github.com/Jeremy95-Sze" title="Jeremy Sze的github">Jeremy Sze的github</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://laoer123.gitee.io/laoer123/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
    <footer id="footer">
    <div class="container">
        &copy; 2023 <a href="https://laoer123.gitee.io/laoer123">Jeremy Sze的博客 By Jeremy Sze</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="https://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/flysnow-org/maupassant-hugo" target="_blank">maupassant</a>.
        
    </div>
</footer>


    
    <script src="//cdnjs.cloudflare.com/ajax/libs/webfont/1.6.28/webfontloader.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js" crossorigin="anonymous"></script>
        <script>(function () {
            if (!window.Diagram) return;
            const blocks = document.querySelectorAll('pre code.language-sequence');
            for (let i = 0; i < blocks.length; i++) {
                const block = blocks[i];
                
                const rootElement = block.parentNode;
                const container = document.createElement('div');
                const id = `js-sequence-diag-${i}`;
                container.id = id;
                container.className = 'align-center';
                container.setAttribute("style", "overFlow-x:auto");
                rootElement.parentNode.replaceChild(container, rootElement);

                const diagram = Diagram.parse(block.childNodes[0].nodeValue);
                diagram.drawSVG(id, window.sequenceDiagramsOptions
                    ? window.sequenceDiagramsOptions
                    : { theme: 'simple' });
            }
        })();
        </script><script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>


<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/laoer123/js/totop.js?v=0.0.0' async=""></script>

<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'GA ID', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/laoer123/js/douban.js'></script>

</body>

</html>